
/**
 @file sys_tmm_flexe.h

 @author  Copyright (C) 2019 Centec Networks Inc.  All rights reserved.

 @date 2019-10-29

 @version v2.0

*/

#ifndef _SYS_TMM_FLEXE_H
#define _SYS_TMM_FLEXE_H
#ifdef __cplusplus
extern "C" {
#endif

/****************************************************************
 *
 * Header Files
 *
 ***************************************************************/


/****************************************************************
*
* Defines and Macros
*
****************************************************************/

#define TMM_MAX_SERDES_NUM_PER_CS          8
#define TMM_MAX_CS_NUM_PER_SHIM            2

#define TMM_MAX_FLEXE_SHIM_CNT             2
#define TMM_GROUP_MAX_PHY_CNT              8

#define SYS_TMM_FLEXE_GET_FLEXE_SHIM(serdes_id)\
    ((serdes_id >= 32) && (serdes_id <= 47)) ? (0) : \
    (((serdes_id >= 80) && (serdes_id <= 95)) ? (1) :(SYS_FLEXE_UNSUPP))

#define SYS_TMM_FLEXE_CS_2_SHIM(cs_id, flexe_shim_id)              \
{                                                     \
    if ((0 == cs_id) || (1 == cs_id))                 \
    {                                                 \
        flexe_shim_id = 0;                            \
    }                                                 \
    else if ((2 == cs_id) || (3 == cs_id))            \
    {                                                 \
        flexe_shim_id = 1;                            \
    }                                                 \
    else                                              \
    {                                                 \
        flexe_shim_id = SYS_FLEXE_UNSUPP;             \
    }                                                 \
}

#define SYS_TMM_FLEXE_SERDES_2_CS(serdes_id, cs)              \
{                                                     \
    if ((serdes_id >= 32) && (serdes_id <= 39))       \
    {                                                 \
        cs = 0;                                       \
    }                                                 \
    else if ((serdes_id >= 40) && (serdes_id <= 47))  \
    {                                                 \
        cs = 1;                                       \
    }                                                 \
    else if ((serdes_id >= 80) && (serdes_id <= 87))  \
    {                                                 \
        cs = 2;                                       \
    }                                                 \
    else if ((serdes_id >= 88) && (serdes_id <= 95))  \
    {                                                 \
        cs = 3;                                       \
    }                                                 \
    else                                              \
    {                                                 \
        cs = 0xff;                                    \
    }                                                 \
}

#define SYS_TMM_FLEXE_CS_2_TXQM(cs, txqm)  \
{                                          \
    switch (cs)                            \
    {                                      \
    case 1:                                \
        txqm = 3;                          \
        break;                             \
    case 2:                                \
        txqm = 6;                          \
        break;                             \
    case 3:                                \
        txqm = 7;                          \
        break;                             \
    case 0:                                \
    default:                               \
        txqm = 2;                          \
        break;                             \
    }                                      \
}

#define SYS_FLEXE_CS_2_BASE_LOGIC_SERDES(cs, logic_serdes)   \
{                                                            \
    switch (cs)                                              \
    {                                                        \
    case 1:                                                  \
        logic_serdes = 40;                                   \
        break;                                               \
    case 2:                                                  \
        logic_serdes = 80;                                   \
        break;                                               \
    case 3:                                                  \
        logic_serdes = 88;                                   \
        break;                                               \
    case 0:                                                  \
    default:                                                 \
        logic_serdes = 32;                                   \
        break;                                               \
    }                                                        \
}

#define SYS_TMM_GET_RLMCS(serdes_id, cs)              \
{                                                     \
    if ((serdes_id >= 32) && (serdes_id <= 39))       \
    {                                                 \
        cs = 0;                                       \
    }                                                 \
    else if ((serdes_id >= 40) && (serdes_id <= 47))  \
    {                                                 \
        cs = 1;                                       \
    }                                                 \
    else if ((serdes_id >= 80) && (serdes_id <= 87))  \
    {                                                 \
        cs = 2;                                       \
    }                                                 \
    else if ((serdes_id >= 88) && (serdes_id <= 95))  \
    {                                                 \
        cs = 3;                                       \
    }                                                 \
    else                                              \
    {                                                 \
        cs = 0xff;                                    \
    }                                                 \
}


#define SYS_FLEXE_SHIM_2_BASE_LOGIC_SERDES(flexe_shim_id, logic_serdes)   \
{                                                            \
    switch (flexe_shim_id)                                   \
    {                                                        \
    case 1:                                                  \
        logic_serdes = 80;                                   \
        break;                                               \
    case 0:                                                  \
    default:                                                 \
        logic_serdes = 32;                                   \
        break;                                               \
    }                                                        \
}

#define SYS_TMM_FLEXE_PHY_2_INST_CNT(phy_speed)      \
    (CTC_PORT_SPEED_400G == phy_speed)      ? 8 :    \
        ((CTC_PORT_SPEED_200G == phy_speed) ? 4 :    \
        ((CTC_PORT_SPEED_100G == phy_speed) ? 2 : 1))

#define SYS_FLEXE_SPEED_VAL_TO_MODE(val, mode)                                   \
{                                                                                \
    if ((val) >= 400)                           (mode) = CTC_PORT_SPEED_400G;    \
    else if (((val) >= 200) && ((val) < 400))  (mode) = CTC_PORT_SPEED_200G;    \
    else if (((val) >= 100) && ((val) < 200))  (mode) = CTC_PORT_SPEED_100G;    \
    else if (((val) >= 50) && ((val) < 100))   (mode) = CTC_PORT_SPEED_50G;     \
    else if (((val) >= 40) && ((val) < 50))    (mode) = CTC_PORT_SPEED_40G;     \
    else if (((val) >= 25) && ((val) < 40))    (mode) = CTC_PORT_SPEED_25G;     \
    else if (((val) >= 20) && ((val) < 25))    (mode) = CTC_PORT_SPEED_20G;     \
    else if (((val) >= 10) && ((val) < 20))    (mode) = CTC_PORT_SPEED_10G;     \
    else if (((val) >= 5) && ((val) < 10))     (mode) = CTC_PORT_SPEED_5G;      \
    else                                        (mode) = CTC_PORT_SPEED_MAX;     \
}

#define SYS_FLEXE_MAC_RX_BUF(speed, buf)      \
{                                             \
    if (speed < 5)                            \
    {                                         \
        buf = 0xa0;                           \
    }                                         \
    else if ((speed >= 5) && (speed < 25))    \
    {                                         \
        buf = 4;                              \
    }                                         \
    else if ((speed >= 25) && (speed < 40))   \
    {                                         \
        buf = 8;                              \
    }                                         \
    else if ((speed >= 40) && (speed < 100))  \
    {                                         \
        buf = 16;                             \
    }                                         \
    else if ((speed >= 100) && (speed < 200)) \
    {                                         \
        buf = 32;                             \
    }                                         \
    else if ((speed >= 200) && (speed < 300)) \
    {                                         \
        buf = 64;                             \
    }                                         \
    else if ((speed >= 300) && (speed <= 400))\
    {                                         \
        buf = 128;                            \
    }                                         \
}


#define SYS_TMM_FLEXE_CLIENT_XC_2_SHIM_CHID(xc_chid)    ((0 == xc_chid) ? 64 : xc_chid)
#define SYS_TMM_FLEXE_CLIENT_SHIM_2_XC_CHID(shim_chid)  ((64 == shim_chid) ? 0 : shim_chid)
#define SYS_TMM_FLEXE_GET_CLIENT_CYCLE(slot_heng) ((slot_heng % MCHIP_CAP(SYS_CAP_FLEXE_MAX_SLOT_PER_INST) * MCHIP_CAP(SYS_CAP_FLEXE_MAX_INST_CNT)) + (slot_heng / MCHIP_CAP(SYS_CAP_FLEXE_MAX_SLOT_PER_INST)))
#define SYS_TMM_FLEXE_GET_SLOT_HENG(client_cycle) ((client_cycle / MCHIP_CAP(SYS_CAP_FLEXE_MAX_INST_CNT)) + (client_cycle % MCHIP_CAP(SYS_CAP_FLEXE_MAX_INST_CNT) * MCHIP_CAP(SYS_CAP_FLEXE_MAX_SLOT_PER_INST)))


enum sys_tmm_flexe_adjust_afull_thrd_type_e
{
    SYS_TMM_FLEXE_ADJ_AFULL_THRD_TYPE_BIND = 0,
    SYS_TMM_FLEXE_ADJ_AFULL_THRD_TYPE_UNBIND,
    SYS_TMM_FLEXE_ADJ_AFULL_THRD_TYPE_MAX
};
typedef enum sys_tmm_flexe_adjust_afull_thrd_type_e sys_tmm_flexe_adjust_afull_thrd_type_t;

enum sys_tmm_flexe_mem_mgr_op_e
{
    SYS_TMM_FLEXE_MEM_MGR_OP_FREE = 0,
    SYS_TMM_FLEXE_MEM_MGR_OP_MALLOC,
    SYS_TMM_FLEXE_MEM_MGR_OP_MAX
};
typedef enum sys_tmm_flexe_mem_mgr_op_e sys_tmm_flexe_mem_mgr_op_t;

#ifdef __cplusplus
}
#endif

#endif
